package com.wjr.braveheart.ui.mvp;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;

import com.wjr.braveheart.ui.activity.AppActivity;
import com.wjr.braveheart.ui.mvp.proxy.ActivityMvpProxy;
import com.wjr.braveheart.ui.mvp.proxy.ActivityMvpProxyImpl;

/**
 * 使用注解 @InjectPresenter 声明 Presenter
 * 通过 MvpProxyImpl 中的方法创建、绑定和解绑 Presenter
 * ================================
 * ==  @InjectPresenter       =====
 * ==  Presenter mPresenter;  =====
 * ================================
 */
public abstract class MvpBaseActivity extends AppActivity implements IMvpBaseView {

    private ActivityMvpProxy mMvpProxy;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        mMvpProxy = createMvpProxy();
        mMvpProxy.createAndBindPresenter();
        super.onCreate(savedInstanceState);
    }

    private ActivityMvpProxy createMvpProxy() {
        if (mMvpProxy == null) {
            mMvpProxy = new ActivityMvpProxyImpl<>(this);
        }
        return mMvpProxy;
    }

    @Override
    public void unbindView() {
        super.unbindView();
        mMvpProxy.unbindPresenter();
    }

    //***************************************IBaseView方法实现-START*************************************
    @Override
    public Context getContext() {
        return super.getContext();
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void dismissLoading() {

    }

    @Override
    public void onEmpty(String emptyData) {

    }

    @Override
    public void onError(int errorCode, String errorMsg) {
        Log.e("MvpBaseActivity.java", "errorCode: " + errorCode + " errorMsg: " + errorMsg);
    }
    //***************************************IBaseView方法实现-END*************************************

}
